package makex

import (
	"fmt"

	"std/abcx"

	"github.com/gookit/color"
)

var (
	size = 1024
)

type New struct {
}

func (r New) arr() {
	list := new([]int)
	fmt.Println("new，它返回的永远是类型的指针，指向分配类型的内存地址")
	fmt.Println("make也是用于内存分配的，但是和new不同，它只用于chan、map以及切片的内存创建，而且它返回的类型就是这三个类型本身")
	color.Yellowln("聲明返回指針", list == nil, "沒給內存空間", *list == nil)
	*list = append(*list, 9, 8, 7, 6, 5)
	color.Redln(list)
	s2 := []int{1, 2, 3, 4}
	copy((*list)[:], s2)
	color.Redln(list)
}

func (r New) mapx() {
	list := new(map[string]any) //entry in nil map
	color.Yellowln(list == nil, *list == nil)
	(*list)["as"] = "as"
	color.Greenln(list)
}

func (r New) basic() {
	s := new(string)
	color.Redln(s, ":", *s)
	ii := new(int)
	color.Redln(ii, ":", *ii)
}
func (r New) structx() {
	h := new(abcx.Person) //分配空間
	color.Redln(h, ":", *h)
}
